package com.changy.ai_tutor_for_dm.controller;

import com.changy.ai_tutor_for_dm.entity.User;
import com.changy.ai_tutor_for_dm.result.Result;
import com.changy.ai_tutor_for_dm.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public Result login(@RequestBody User user) {

        String token = loginService.login(user);

        if (token == null) {
            return Result.error("登录失败，手机号或密码错误");
        }
        else return Result.success(token);
    }

}
